home *** CD-ROM | disk | FTP | other *** search
/ Suzy B Software 2 / Suzy B Software CD-ROM 2 (1994).iso / extras / programm / gemfsc20 / gemfsc20.lzh / GEMFUNCS / RSCRRBTN.C < prev    next >
C/C++ Source or Header  |  1993-03-20  |  4KB  |  148 lines

  1. /**************************************************************************
  2.  * RSCRRBTN.C - The obj_rrbuttons() routine.
  3.  *     This changes the specified objects into rounded-rectangle radio
  4.  *     buttons (by making them USERDEF objects), and supplies the drawing
  5.  *     routine for the buttons.
  6.  *************************************************************************/
  7.  
  8. #include "gemfintl.h"
  9. #include <string.h>
  10.  
  11. /*-------------------------------------------------------------------------
  12.  * rr_draw - Draw a rounded rectangle radio button.  This routine is
  13.  *
  14.         called by the AES whenever a rrbutton needs to be drawn
  15.  *             or to have its state changed.    (Note that this routine
  16.  *             gets control in supervisor mode.  Some runtime libraries
  17.  *             will crash on stack overlow problems if you make calls
  18.  *             to DOS, BIOS, or XBIOS from in here.)
  19.  *
  20.  *             We handle SELECTED and DISABLED states here, but other
  21.  *             states are handled by the AES because we pass the states we
  22.  *             didn't do back to the AES as the retval from this routine.
  23.  *-----------------------------------------------------------------------*/
  24.  
  25. #ifdef GEMFAST_PROTOS
  26.   static long GCALLBACK rr_draw(XPARMBLK *parmblk)
  27. #else
  28.   static long GCALLBACK rr_draw(parmblk)
  29.     register XPARMBLK *parmblk;
  30. #endif
  31. {
  32.     short    vdi_handle;
  33.     short    xpos;
  34.     short    ypos;
  35.     short    dmy;
  36.     short    len;
  37.     short    objstate;
  38.     VRECT    cliprect;
  39.     VRECT    boxrect;
  40.  
  41.     if (0 == (vdi_handle = apl_vshared())) {
  42.         return 0;    /* oh well, so sorry */
  43.     }
  44.  
  45.     objstate = parmblk->currstate;
  46.  
  47.     rc_gtov(&parmblk->cliprect, &cliprect);
  48.     vs_clip(vdi_handle, 1, (short *)&cliprect);
  49.  
  50.     rc_gtov(&parmblk->drawrect, &boxrect);
  51.     rc_vadjust(&boxrect, 1, 1);
  52.  
  53.     len = (short)strlen((char *)parmblk->pub->ob_spec);
  54.  
  55.     xpos = parmblk->drawrect.g_x +
  56.                 ((parmblk->drawrect.g_w - gl_wchar * len) / 2);
  57.     ypos = parmblk->drawrect.g_y +
  58.                 ((parmblk->drawrect.g_h - gl_hchar) / 2);
  59.  
  60.     if (objstate & SELECTED) {
  61.         v_rfbox(vdi_handle, (short *)&boxrect);
  62.         vswr_mode(vdi_handle, MD_TRANS);
  63.         vst_color(vdi_handle, 0);
  64.     } else {
  65.         vsf_interior(vdi_handle, IS_HOLLOW);
  66.         v_rfbox(vdi_handle, (short *)&boxrect);
  67.         vsf_interior(vdi_handle, IS_SOLID);
  68.     }
  69.  
  70.     if (objstate & DISABLED) {
  71.         vst_effects(vdi_handle, 0x0002); /* lightened text */
  72.     }
  73.     vst_alignment(vdi_handle, 0, 5, &dmy, &dmy);
  74.     v_gtext(vdi_handle, xpos, ypos, (char *)parmblk->pub->ob_spec);
  75.     vst_alignment(vdi_handle, 0, 0, &dmy, &dmy);
  76.     if (objstate & DISABLED) {
  77.         vst_effects(vdi_handle, 0x0000); /* normal text */
  78.     }
  79.  
  80.     if (objstate & SELECTED) {
  81.         vst_color(vdi_handle, 1);
  82.         vswr_mode(vdi_handle, MD_REPLACE);
  83.     }
  84.  
  85.     vs_clip(vdi_handle, 0, (short *)&cliprect);
  86.  
  87.     return (objstate & ~(SELECTED|DISABLED));
  88. }
  89.  
  90. /*-------------------------------------------------------------------------
  91.  * rsc_rrbuttons - Transform all radio buttons into rounded radio buttons.
  92.  *-----------------------------------------------------------------------*/
  93.  
  94. short rsc_rrbuttons(ptree)
  95.     OBJECT             *ptree;
  96. {
  97.     register OBJECT   *pobj;
  98.     register XUSERBLK *pblk;
  99.     register short         obflags;
  100.     register short         numobj = 0;
  101.     register short         curobj;
  102.  
  103.     if (0 == apl_vshared()) {
  104.         return gfErr_vdi_handle;             /* no more handles */
  105.     }
  106.  
  107. /*
  108.  * count the number of button objects we'll be transforming...
  109.  */
  110.  
  111.     for (pobj = ptree; ; ++pobj) {
  112.         obflags = pobj->ob_flags;
  113.         if ((pobj->ob_type & 0x00FF) == G_BUTTON && (obflags & RBUTTON)) {
  114.             ++numobj;
  115.         }
  116.         if (obflags & LASTOB) {         /* stop after doing last    */
  117.             break;                        /* object in the tree.        */
  118.         }
  119.     }
  120.  
  121. /*
  122.  * allocate a chunk of memory to hold all the XUSERBLKs we're going
  123.  * to attach to the objects.
  124.  */
  125.  
  126.     if (NULL == (pblk = apl_malloc((long)(numobj * sizeof(XUSERBLK))))) {
  127.         return gfErr_no_memory;
  128.     }
  129.  
  130. /*
  131.  * now go through and change each radio button object into a USERDEF.
  132.  */
  133.  
  134.     for (curobj = 0, pobj = ptree; ; ++curobj, ++pobj) {
  135.         obflags = pobj->ob_flags;
  136.         if ((pobj->ob_type & 0x00FF) == G_BUTTON && (obflags & RBUTTON)) {
  137.             obj_mxuserdef(ptree, curobj, pblk++, rr_draw, NULL, 0L);
  138.         }
  139.         if (obflags & LASTOB) {         /* stop after doing last    */
  140.             break;                        /* object in the tree.        */
  141.         }
  142.     }
  143.  
  144.     return 0;
  145. }
  146.  
  147.  
  148.